<template name="ChatpalSearchResultTemplate">
	<div class="chatpal-search-container">
		<ul class="chatpal-search-typefilter">
			<li value="All" class="{{navSelected 'All'}}">{{_ "Chatpal_All_Results"}}</li>
			<li value="Room" class="{{navSelected 'Room'}}">{{_ "Chatpal_Current_Room_Only"}}</li>
			<li value="Messages" class="{{navSelected 'Messages'}}">{{_ "Chatpal_Messages_Only"}}</li>
		</ul>
		<div class="chatpal-search-result">
			{{#if searching}}
				<div class="chatpal_search-loader">
					{{> loading}}
				</div>
			{{else}}
				{{#unless result}}
					<p class="chatpal-search-welcome">
						{{_ "Chatpal_Welcome"}}
					</p>
				{{/unless}}
				{{#if $eq resultType "All"}}
					{{#if result.user.docs}}
						<div class="chatpal-search-result-header">
							{{_ "Chatpal_Users"}}
						</div>
						<div class="chatpal-search-result-list">
							{{#each result.user.docs}}
								{{> ChatpalSearchSingleUser}}
							{{/each}}
						</div>
					{{/if}}
					{{#if result.room.docs}}
						<div class="chatpal-search-result-header">
							{{_ "Chatpal_Rooms"}}
						</div>
						<div class="chatpal-search-result-list">
							{{#each result.room.docs}}
								{{> ChatpalSearchSingleRoom}}
							{{/each}}
						</div>
					{{/if}}
					{{#if result.message.docs}}
						<div class="chatpal-search-result-header">
							{{_ "Chatpal_Messages"}}
						</div>
						<div class="chatpal-search-result-list">
							{{#each result.message.docs}}
								{{> ChatpalSearchSingleMessage}}
							{{/each}}
						</div>
						{{#if moreMessagesThanDisplayed}}
							<div class="chatpal-show-more-messages">{{_
									"Chatpal_More"}}</div>
						{{/if}}
					{{/if}}

					{{#if $not resultsFoundForAllSearch}}
						<div class="chatpal-search-result-header">
							<h2 class="chatpal-search-number">
								<h2>{{_ "Chatpal_No_Results"}}</h2>
							</h2>
						</div>
					{{/if}}
				{{/if}}
				{{#if resultMessagesOnly}}
					<div class="chatpal-search-result-header">
						<h2 class="chatpal-search-number">
							{{#if resultNumFound}}
								{{resultNumFound}}
							{{/if}}
						</h2>
					</div>
					{{#if result.message}}
						<div class="chatpal-search-result-list">
							{{#each result.message.docs}}
								{{> ChatpalSearchSingleMessage}}
							{{/each}}
						</div>
					{{/if}}
					{{#if resultPaging}}
						{{#if $neq resultPaging.numOfPages 0}}
							<div class="chatpal-paging">
								{{#if $gt resultPaging.currentPage 1}}
									<div class="chatpal-paging-prev chatpal-paging-button">
										<i class="icon-left-circled2"></i>
									</div>
								{{/if}}
								<div class="chatpal-paging-text">{{_ "Chatpal_search_page_of"
																	 resultPaging.currentPage
																	 resultPaging.numOfPages}}</div>
								{{#if $lt resultPaging.currentPage resultPaging.numOfPages}}
									<div class="chatpal-paging-next chatpal-paging-button">
										<i class="icon-right-circled2"></i>
									</div>
								{{/if}}
							</div>
						{{/if}}
					{{/if}}
				{{/if}}
			{{/if}}
		</div>
	</div>
</template>

<template name="ChatpalSearchSingleMessage">
	<div class="chatpal-search-result-single">
		<h2>
			<span class="chatpal-channel">
				{{> icon icon=roomIcon}}
				{{roomName}}</span>
			<a class="chatpal-link" href="{{roomLink}}?msg={{_id}}">{{_ "Chatpal_go_to_message"}}</a>
			<span class="chatpal-date">{{date}}</span>
		</h2>
		<div class="chatpal-avatar">
			<div class="chatpal-avatar-image"
				 style="background-image:url({{getAvatarUrl username }});"></div>
		</div>
		<span class="chatpal-name">{{username}}</span>
		<span class="chatpal-time">{{time}}</span>
		<div class="chatpal-message">{{{text}}}</div>
		{{#if roomNotSubscribed}}
			<div class="chatpal-info color-info-font-color"><i>{{{_ "Chatpal_channel_not_joined_yet"}}}</i></div>
		{{/if}}
	</div>
</template>

<template name="ChatpalSearchSingleUser">
	<div class="chatpal-search-result-user">
		<div class="chatpal-avatar">
			<div class="chatpal-avatar-image" style="background-image:url({{ getAvatarUrl cleanUsername }});"></div>
		</div>
		<h2>{{{user_name}}}</h2>
		<div class="direct-message">
			<a href="{{ getDMUrl cleanUsername }}">{{_ "Chatpal_go_to_user"}}</a>
		</div>
	</div>
</template>

<template name="ChatpalSearchSingleRoom">
	<div class="chatpal-search-result-user chatpal-search-result-room">
		<h2>
			<span class="chatpal-channel">
				{{> icon icon=roomIcon}}
				{{{room_name}}}</span>
			<a class="chatpal-link" href="{{roomLink}}">{{_ "Chatpal_go_to_room"}}</a>
		</h2>
		<div class="chatpal-search-pills">
			{{#if room_topic}}
				<div class="chatpal-search-pills-topic">{{{room_topic}}}</div>
			{{/if}}
			{{#if room_description}}
				<div class="chatpal-search-pills-description">{{{room_description}}}</div>
			{{/if}}
			{{#if room_announcement}}
				<div class="chatpal-search-pills-announcement">{{{room_announcement}}}</div>
			{{/if}}
		</div>
		{{#if roomNotSubscribed}}
			<div class="chatpal-info color-info-font-color"><i>{{{_ "Chatpal_channel_not_joined_yet"}}}</i></div>
		{{/if}}
	</div>
</template>
